<%@ page import="Pojo.Journalism" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="viewport" content="width=device-width,initical-scale=1.0"/>
    <link rel="stylesheet" href="./css/bootstrap.css"/>
    <link rel="stylesheet" href="./css/nrgl.css"/>

    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".updatainfo").click(function () {
                var id = $(this).val();
                $.get("Updata", {
                    id: id,
                }, function (data) {
                    window.location.href = data;
                })
            })
            $(".delectuinfo").click(function () {
                var id = $(this).val();
                $.post("Delect", {id: id,}, function (data) {
                    if (data == 1) {
                        alert("删除成功！");
                        window.location.href = "http://localhost:8080/xinwen_war/infomanager.jsp";
                    } else {
                        alert("删除失败！")
                    }
                });
            })
        })
    </script>
    <style>
        .updatainfo, .delectuinfo {
            border: 1px solid;
            color: #333;
            background-color: #fff;
            border-color: #6e5454;
            width: 68px;
            margin: 1px;
        }
    </style>
</head>
<body>
<nav class="navbar head" role="navigation" id="nav">
    <div class="col-md-1"></div>
    <div class="col-md-10">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand logo" href="#">后台管理</a>
                <button class="navbar-toggle aa" data-toggle="collapse" data-target="#navbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="index.jsp"><i class="glyphicon glyphicon-home"></i>后台管理</a></li>
                    <li><a href="用户管理.jsp"><i class="glyphicon glyphicon-user"></i>用户管理</a></li>
                    <li><a href="infomanager.jsp"><i class="glyphicon glyphicon-list-alt"></i>内容管理</a></li>
                    <li><a href="body.jsp"><i class="glyphicon glyphicon-list-alt"></i>前台首页</a></li>
                </ul>
                <ul class="navbar-nav nav navbar-right">
                    <li class="dropdown">
                        <a href="" class="dropdown-toggle" data-toggle="dropdown">
                            <%=request.getSession().getAttribute("username")%><span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href=""><i class="glyphicon glyphicon-cog"></i>个人主页</a></li>
                            <li><a href=""><i class="glyphicon glyphicon-screenshot"></i>个人设置</a></li>
                            <li><a href=""><i class="glyphicon glyphicon-credit-card"></i>账户中心</a></li>
                            <li><a href=""><i class="glyphicon glyphicon-heart"></i>我的收藏</a></li>
                        </ul>
                    </li>
                    <li><a href="Cancellation.jsp"><i class="glyphicon glyphicon-off"></i>退出</a></li>
                </ul>

            </div>
        </div>
    </div>
    <div class="col-md-1"></div>
</nav>
<div class="main clearfix">
    <div class="col-md-1"></div>
    <div class="col-md-2">
        <ul class="left nav">
            <li class="active"><a href="#dz" data-toggle='tab'>内容管理</a></li>
            <li class="nor"><a href="#aq" data-toggle='tab'>添加内容</a></li>
        </ul>
    </div>
    <div class="col-md-8">

        <h2 class='page-header'>内容管理</h2>

        <ul class='nav nav-tabs'>
            <li class="active"><a href="#dz" data-toggle='tab'>内容管理</a></li>

            <li><a href="#aq" data-toggle='tab'>添加内容</a></li>

        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id='dz'>
                <table class="table">
                    <thead>
                    <tr>
                        <th class="th">文章标题</th>
                        <th class="th">发布时间</th>
                        <th class="th">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${newInfo}" varStatus="i" var="li">
                        <tr>
                            <td class="th">${li.title}</td>
                            <td>${li.time}</td>
                            <td class="dropdown">
                                <button class='btn btn-default' data-toggle='dropdown'>
                                    操作<span class='caret'></span>
                                </button>
                                <ul class="dropdown-menu" style="min-width: 72px;">
                                    <li>
                                        <button class="updatainfo" value="${li.id}">编辑</button>
                                    </li>
                                    <li>
                                        <button class="delectuinfo" value="${li.id}">删除</button>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <ul>
                    <%
                        Journalism j = (Journalism) request.getSession().getAttribute("journalism");
                        double x = j.getNewnum();
                        int n = (int) Math.ceil(x/10);
                        int nn = (int) request.getSession().getAttribute("index");
                        int m = nn/10+1;
                    %>
                    <li style="margin: 0px 0% 0px 90%;">共<%=n%>页     当前第<%=m%>页</li>
                </ul>
                <ul class='pagination  fenye' id='page'>
                    <li>
                        <button id="up">上一页</button>
                    </li>
                    <li>
                        <button id="up1">&laquo;</button>
                    </li>
                    <%
                        int i = 0;
                        for (i = 1; i <= n; i++) {
//                            out.println(x/10);
                    %>
                    <li>
                        <button class="jump" value="<%=i%>"><%=i%>
                        </button>
                    </li>
                    <%
                        }
                    %>
                    <li>
                        <button id="down">&raquo;</button>
                    </li>
                    <li>
                        <button id="down1">下一页</button>
                    </li>
                </ul>
            </div>

            <div class="tab-pane add" id='aq'>
                <form action="NewInfo" method='get'>
                    <div class='form-group has-success'>
                        <label for='Name'>标题：</label>
                        <input type="text" placeholder="请输入文章标题" id='Name' class='form-control has-success'
                               name="title"/>
                    </div>
                    <div class='form-group has-success'>
                        <label for='Name'>简略内容：</label>
                        <input type="text" placeholder="请输入简略内容" id='Name1' class='form-control has-success'
                               name="simply"/>
                    </div>
                    <div class='form-group has-warning'>
                        <label>文章内容：</label>
                        <textarea placeholder="请输入文章内容" class='form-control' rows="15" name="content"></textarea>
                    </div>
                    <div class='form-group has-warning'>
                        <div class='col-sm-4'>
                            <div class='checkbox-inline'>
                                <select style="width: 70px;height: 30px;" name="type">
                                    <option value="">类型</option>
                                    <option value="体育">体育</option>
                                    <option value="娱乐">娱乐</option>
                                    <option value="股票">股票</option>
                                    <option value="财经">财经</option>
                                    <option value="科技">科技</option>
                                    <option value="汽车">汽车</option>
                                </select>
                            </div>
                        </div>
                        <div class='col-sm-2  col-lg-offset-6'>
                            <button class="btn">发布文章</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="col-md-1"></div>
    </div>
</div>
<script type="text/javascript" src="./js/jquery.js"></script>
<script type="text/javascript" src="./js/bootstrap.js"></script>
</body>
<script type="text/javascript">
    $(document).ready(function () {
        $(".jump").click(function () {
            var jump = $(this).val();
            $.get("Limit", {jump: jump,}, function (data) {
                if (data == 1) {
                    window.location.href = "http://localhost:8080/xinwen_war/infomanager.jsp";
                }
            });
        })
        $("#up").click(function () {
            var what = "up";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前已经是第一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/infomanager.jsp";
                }
            });
        })
        $("#up1").click(function () {
            var what = "up";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前已经是第一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/infomanager.jsp";
                }
            });
        })
        $("#down").click(function () {
            var what = "down";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前是最后一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/infomanager.jsp";
                }
            });
        })
        $("#down1").click(function () {
            var what = "down";
            $.post("Limit", {what: what,}, function (data) {
                if (data == 1) {
                    alert("当前是最后一页");
                } else {
                    window.location.href = "http://localhost:8080/xinwen_war/infomanager.jsp";
                }
            });
        })
    })
</script>
</html>